package GUI;

import Logica.Treatment1;

import java.awt.Color;
import java.awt.Dimension;

import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class ModificarTratamiento1 extends JFrame {
  private JLabel jlabelAgregarT = new JLabel();
  private JLabel numEx = new JLabel();
  private JLabel des = new JLabel();
  private JLabel cos = new JLabel();
  private JLabel cant = new JLabel();
  private JLabel obs = new JLabel();
  private JLabel bd = new JLabel();
  private JLabel ed= new JLabel();
  private JLabel numTr = new JLabel();
  private JButton jButtonGuardarTre = new JButton();
  private JFormattedTextField jForNoTreat = new JFormattedTextField();
  private JFormattedTextField jFormDescri = new JFormattedTextField();
  private JFormattedTextField jFormCost = new JFormattedTextField();
  private JFormattedTextField jFormCant = new JFormattedTextField();
  private JFormattedTextField jFormObs = new JFormattedTextField();
  private JFormattedTextField jFormFechaIn = new JFormattedTextField();
  private JFormattedTextField jFormFechaFin = new JFormattedTextField();
  private JFormattedTextField jFormNoExa = new JFormattedTextField();
  
  Treatment1 trea=new Treatment1();
  
  private JLabel jLabelPonerFecha1 = new JLabel();
  private JLabel jLabelPonerFecha2 = new JLabel();
  private Object[] informacion;
  private JButton jButtonEliminar = new JButton();

  public ModificarTratamiento1(Object[] info) {
    try {
      informacion = info;
      jbInit(info);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit(Object[] info) throws Exception {    
    this.getContentPane().setLayout( null );
    this.setSize(new Dimension(528, 575));
    this.setTitle("Agregar Tratamiento");
    this.setFont(new Font("Dialog", 0, 20));
    jlabelAgregarT.setText("MODIFICAR TRATAMIENTO");
    jlabelAgregarT.setBounds(new Rectangle(125, 15, 245, 50));
    jlabelAgregarT.setFont(new Font("Tahoma", 0, 20));
    jlabelAgregarT.setForeground(new Color(15, 9, 189));
    numEx.setText("No. Tratamiento");
    numEx.setBounds(new Rectangle(20, 80, 160, 40));
    numEx.setFont(new Font("Tahoma", 0, 14));
    des.setText("Descripcion");
    des.setBounds(new Rectangle(20, 115, 160, 40));
    des.setFont(new Font("Tahoma", 0, 14));
    cos .setText("Costo");
    cos .setBounds(new Rectangle(20, 160, 160, 40));
    cos .setFont(new Font("Tahoma", 0, 14));
    cant.setText("Cantidad");
    cant.setBounds(new Rectangle(15, 215, 105, 40));
    cant.setFont(new Font("Tahoma", 0, 14));
    obs.setText("Observaciones");
    obs.setBounds(new Rectangle(10, 265, 160, 40));
    obs.setFont(new Font("Tahoma", 0, 14));
    bd.setText("Fecha Inicio");
    bd.setBounds(new Rectangle(15, 320, 95, 40));
    bd.setFont(new Font("Tahoma", 0, 14));
    ed.setText("Fecha Final");
    ed.setBounds(new Rectangle(20, 375, 160, 40));
    ed.setFont(new Font("Tahoma", 0, 14));
    numTr.setText("No. Examen");
    numTr.setBounds(new Rectangle(15, 435, 100, 40));
    numTr.setFont(new Font("Tahoma", 0, 14));
    jButtonGuardarTre.setText("GUARDAR");
    jButtonGuardarTre.setBounds(new Rectangle(375, 495, 130, 40));
    jButtonGuardarTre.setFont(new Font("Arial Black", 0, 11));

    jButtonGuardarTre.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          jButtonGuardarTre_actionPerformed(e);
        }
      });
    jForNoTreat.setBounds(new Rectangle(120, 80, 270, 35));
    jForNoTreat.setFont(new Font("Tahoma", 0, 14));
    jForNoTreat.setText(String.valueOf(info[0]));
    jFormDescri.setBounds(new Rectangle(120, 120, 270, 40));
    jFormDescri.setText(String.valueOf(info[1]));
    jFormCost.setBounds(new Rectangle(120, 170, 270, 35));
    jFormCost.setText(String.valueOf(info[2]));
    jFormCant.setBounds(new Rectangle(120, 220, 270, 35));
    jFormCant.setText(String.valueOf(info[3]));
    jFormObs.setBounds(new Rectangle(120, 270, 270, 35));
    jFormObs.setText(String.valueOf(info[4]));
    jFormFechaIn.setBounds(new Rectangle(120, 325, 270, 35));
    jFormFechaIn.setText(String.valueOf(info[5]));
    jFormFechaFin.setBounds(new Rectangle(120, 380, 270, 35));
    jFormFechaFin.setText(String.valueOf(info[6]));
    jFormNoExa.setBounds(new Rectangle(120, 440, 270, 35));
    jFormNoExa.setText(String.valueOf(info[7]));
    jLabelPonerFecha1.setText("yyyy-mm-dd");
    jLabelPonerFecha1.setBounds(new Rectangle(405, 325, 105, 35));
    jLabelPonerFecha2.setText("yyyy-mm-dd");
    jLabelPonerFecha2.setBounds(new Rectangle(400, 380, 105, 35));
    this.getContentPane().add(jButtonEliminar, null);
    this.getContentPane().add(jLabelPonerFecha2, null);
    this.getContentPane().add(jLabelPonerFecha1, null);
    this.getContentPane().add(jFormNoExa, null);
    this.getContentPane().add(jFormFechaFin, null);
    this.getContentPane().add(jFormFechaIn, null);
    this.getContentPane().add(jFormObs, null);
    this.getContentPane().add(jFormCant, null);
    this.getContentPane().add(jFormCost, null);
    this.getContentPane().add(jFormDescri, null);
    this.getContentPane().add(jForNoTreat, null);
    this.getContentPane().add(jButtonGuardarTre, null);
    this.getContentPane().add(numTr, null);
    this.getContentPane().add(ed, null);
    this.getContentPane().add(bd, null);
    this.getContentPane().add(obs, null);
    this.getContentPane().add(cant, null);
    this.getContentPane().add(cos , null);
    this.getContentPane().add(des, null);
    this.getContentPane().add(numEx, null);
    this.getContentPane().add(jlabelAgregarT, null);

  }

  private void jButtonGuardarTre_actionPerformed(ActionEvent e) {
// q me guarde las modificaciones 
    String NumTreat=this.jForNoTreat.getText().toString();
    System.out.println("toma num treatment"+NumTreat );
    
    if(!(this.jFormNoExa.getText().toString().equals(String.valueOf(informacion[0])))){
      String nuevoNoEx=this.jFormNoExa.getText().toString();
      System.out.println("agrega exa "+nuevoNoEx );
      trea.modificaTreatmentExaNum(nuevoNoEx,NumTreat);
    }
    if(!(this.jFormDescri.getText().toString().equals(String.valueOf(informacion[1])))){
      String nuevoDes=this.jFormDescri.getText().toString();
      trea.modificaDesc(nuevoDes,NumTreat);
    }
    if(!(this.jFormCost.getText().toString().equals(String.valueOf(informacion[2])))){
      String nuevoCost=this.jFormCost.getText().toString();
      trea.modificaCost(nuevoCost,NumTreat);
    }
    if(!(this.jFormCant.getText().toString().equals(String.valueOf(informacion[3])))){
      String nuevoCant=this.jFormCant.getText().toString();
      trea.modificaTreatmentCantidad(nuevoCant,NumTreat);
    }
    if(!(this.jFormObs.getText().toString().equals(String.valueOf(informacion[4])))){
      String nuevoObs=this.jFormObs.getText().toString();
      trea.modificaTreatmentObserv(nuevoObs,NumTreat);
    }
    if(!(this.jFormFechaIn.getText().toString().equals(String.valueOf(informacion[5])))){
      String nuevoFechaIn=this.jFormDescri.getText().toString();
      trea.modificaTreatmentDateBeg(nuevoFechaIn,NumTreat);
    }
    if(!(this.jFormFechaFin.getText().toString().equals(String.valueOf(informacion[6])))){
      String nuevoFechaFin=this.jFormFechaFin.getText().toString();
      trea.modificaTreatmentDateEnd(nuevoFechaFin,NumTreat);
    }
    if(!(this.jFormNoExa.getText().toString().equals(String.valueOf(informacion[7])))){
        JOptionPane.showMessageDialog(null, "ERROR", "No puede modificar este dato", JOptionPane.ERROR_MESSAGE);  }
    }

}

